package com.primb.bench.common.viewmodel;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.primb.bench.R;
import com.zhy.autolayout.AutoLinearLayout;

/**
 * Created by Chen on 2017/5/10.
 * 功能描述：大文本数据驱动模型
 */

public class ViewBigTextEntity implements Parcelable {
    String title;
    String textContent;

    public ViewBigTextEntity(String key, String value) {
        this.title = key;
        this.textContent = value;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTextContent() {
        return textContent;
    }

    public void setTextContent(String textContent) {
        this.textContent = textContent;
    }

    public void addView(Context context, ViewGroup viewGroup) {
        LinearLayout layout = new AutoLinearLayout(context);
        layout.setOrientation(LinearLayout.HORIZONTAL);
        layout.setBackgroundColor(ContextCompat.getColor(context, R.color.white));
        layout.setGravity(Gravity.CENTER_VERTICAL);

        ImageView ivIcon = new ImageView(context);
        AutoLinearLayout.LayoutParams paramsIcon = new AutoLinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ivIcon.setImageResource(R.mipmap.title_text_icon);
        ivIcon.setLayoutParams(paramsIcon);
        ivIcon.setPadding(40, 40, 0, 40);

        layout.addView(ivIcon);

        TextView tvTitle = new TextView(context);
        if (title != null) {
            tvTitle.setText(title);
        }
        tvTitle.setPadding(30, 20, 30, 20);
        tvTitle.setTextSize(16);
        tvTitle.setTextColor(ContextCompat.getColor(context,R.color.gray_333333));
        layout.addView(tvTitle);

        viewGroup.addView(layout);

        TextView tvContent = new TextView(context);
        tvContent.setGravity(Gravity.LEFT);
        if (title != null) {
            tvContent.setText(textContent);
        }
        tvContent.setPadding(70, 20, 30, 20);
        tvContent.setTextSize(12);
        tvContent.setTextColor(ContextCompat.getColor(context,R.color.gray_999999));
        viewGroup.addView(tvContent);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.title);
        dest.writeString(this.textContent);
    }

    public ViewBigTextEntity() {
    }

    protected ViewBigTextEntity(Parcel in) {
        this.title = in.readString();
        this.textContent = in.readString();
    }

    public static final Creator<ViewBigTextEntity> CREATOR = new Creator<ViewBigTextEntity>() {
        @Override
        public ViewBigTextEntity createFromParcel(Parcel source) {
            return new ViewBigTextEntity(source);
        }

        @Override
        public ViewBigTextEntity[] newArray(int size) {
            return new ViewBigTextEntity[size];
        }
    };
}
